package veterinaria.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.modelo.Persona;
import veterinaria.negocio.GestionDoctor;

/**
 * Servlet implementation class DoctorIngresoServlet
 */
@WebServlet("/DoctorIngresoServlet")
public class DoctorIngresoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoctorIngresoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String pAdm = request.getParameter("cboTipo");		
        String pNom = request.getParameter("txtPerNombre");       
        String pDom = request.getParameter("txtPerDomicilio");       
        String pTel = request.getParameter("txtPerTelefono");       
        String pCel = request.getParameter("txtPerCelular");       
        String pCor = request.getParameter("txtPerCorreo");       
        String pIma = request.getParameter("txtPerImagen");
        String pUsu = request.getParameter("txtUsuCodigo");        
        try {
        	Persona cPer = new Persona();
        	cPer.setPerNombre(pNom);
        	cPer.setPerDomicilio(pDom);
        	cPer.setPerTelefono(pTel);
        	cPer.setPerCelular(pCel);
        	cPer.setPerCorreo(pCor);
        	cPer.setPerImagen(pIma);
            GestionDoctor negocio = new GestionDoctor();
            negocio.insertar(pAdm,pUsu,cPer);
            request.setAttribute("aDoctor", negocio.buscarPorNombre(pNom));
            RequestDispatcher rd = request.getRequestDispatcher("DoctorIngreso.jsp");
            rd.forward(request, response);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }			
	}
}
